<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OpenShoe: interrupt_avr32.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenShoe
   &#160;<span id="projectnumber">0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">interrupt_avr32.h</div>  </div>
</div>
<div class="contents">
<a href="_framework__and__interfaces_2src_2asf_2common_2utils_2interrupt_2interrupt__avr32_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef UTILS_INTERRUPT_INTERRUPT_H</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor">#define UTILS_INTERRUPT_INTERRUPT_H</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;compiler.h&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;preprocessor/tpaste.h&gt;</span>
<a name="l00043"></a>00043 
<a name="l00050"></a>00050 
<a name="l00051"></a>00051 <span class="preprocessor">#if (defined __GNUC__)</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="keyword">typedef</span> void (*__int_handler)(void);
<a name="l00053"></a>00053 <span class="preprocessor">#elif (defined __ICCAVR32__)</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="keyword">typedef</span> void (__interrupt *__int_handler)(void);
<a name="l00055"></a>00055 <span class="preprocessor">#endif</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00062"></a>00062 <span class="preprocessor">#if defined(__GNUC__) || defined(__DOXYGEN__)</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>
<a name="l00099"></a>00099 <span class="preprocessor">#  define ISR(func, int_grp, int_lvl)    \</span>
<a name="l00100"></a>00100 <span class="preprocessor">        __attribute__((__interrupt__)) static void func (void)</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span>
<a name="l00102"></a>00102 <span class="preprocessor">#elif defined(__ICCAVR32__)</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#  define ISR0(...) _Pragma(#__VA_ARGS__)</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#  define ISR(func, int_grp, int_lvl)                                          \</span>
<a name="l00105"></a>00105 <span class="preprocessor">                ISR0(handler=int_grp, int_lvl)                                 \</span>
<a name="l00106"></a>00106 <span class="preprocessor">                  __interrupt static void func (void)</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span>
<a name="l00109"></a>00109 <span class="preprocessor">#if defined(__GNUC__) || defined(__DOXYGEN__) || defined(CONFIG_INTERRUPT_FORCE_INTC)</span>
<a name="l00110"></a>00110 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;intc.h&gt;</span>
<a name="l00111"></a>00111 
<a name="l00125"></a>00125 <span class="preprocessor">#  define irq_initialize_vectors()    INTC_init_interrupts()</span>
<a name="l00126"></a>00126 <span class="preprocessor"></span>
<a name="l00153"></a>00153 <span class="preprocessor">#  define irq_register_handler(func, int_num, int_lvl)                         \</span>
<a name="l00154"></a>00154 <span class="preprocessor">        INTC_register_interrupt(func, int_num,                                 \</span>
<a name="l00155"></a>00155 <span class="preprocessor">                        TPASTE2(AVR32_INTC_INT, int_lvl))</span>
<a name="l00156"></a>00156 <span class="preprocessor"></span>
<a name="l00157"></a>00157 <span class="preprocessor">#elif defined(__ICCAVR32__)</span>
<a name="l00158"></a>00158 <span class="preprocessor"></span><span class="preprocessor">#  define irq_initialize_vectors()                        do{ } while(0)</span>
<a name="l00159"></a>00159 <span class="preprocessor"></span><span class="preprocessor">#  define irq_register_handler(func, int_num, int_lvl)    do{ } while(0)</span>
<a name="l00160"></a>00160 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span>
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 <span class="preprocessor">#if (defined __GNUC__)</span>
<a name="l00165"></a>00165 <span class="preprocessor"></span><span class="preprocessor">#  define cpu_irq_enable()                             \</span>
<a name="l00166"></a>00166 <span class="preprocessor">        do {                                           \</span>
<a name="l00167"></a>00167 <span class="preprocessor">                barrier();                             \</span>
<a name="l00168"></a>00168 <span class="preprocessor">                __builtin_csrf(AVR32_SR_GM_OFFSET);    \</span>
<a name="l00169"></a>00169 <span class="preprocessor">        } while (0)</span>
<a name="l00170"></a>00170 <span class="preprocessor"></span><span class="preprocessor">#  define cpu_irq_disable()                            \</span>
<a name="l00171"></a>00171 <span class="preprocessor">        do {                                           \</span>
<a name="l00172"></a>00172 <span class="preprocessor">                __builtin_ssrf(AVR32_SR_GM_OFFSET);    \</span>
<a name="l00173"></a>00173 <span class="preprocessor">                barrier();                             \</span>
<a name="l00174"></a>00174 <span class="preprocessor">        } while (0)</span>
<a name="l00175"></a>00175 <span class="preprocessor"></span><span class="preprocessor">#elif (defined __ICCAVR32__)</span>
<a name="l00176"></a>00176 <span class="preprocessor"></span><span class="preprocessor">#  if (defined CONFIG_INTERRUPT_FORCE_INTC)</span>
<a name="l00177"></a>00177 <span class="preprocessor"></span><span class="preprocessor">#    define cpu_irq_enable()                                 \</span>
<a name="l00178"></a>00178 <span class="preprocessor">        do {                                                 \</span>
<a name="l00179"></a>00179 <span class="preprocessor">                barrier();                                   \</span>
<a name="l00180"></a>00180 <span class="preprocessor">                __clear_status_flag(AVR32_SR_GM_OFFSET);     \</span>
<a name="l00181"></a>00181 <span class="preprocessor">        } while(0)</span>
<a name="l00182"></a>00182 <span class="preprocessor"></span><span class="preprocessor">#    define cpu_irq_disable()                                \</span>
<a name="l00183"></a>00183 <span class="preprocessor">        do {                                                 \</span>
<a name="l00184"></a>00184 <span class="preprocessor">                __set_status_flag(AVR32_SR_GM_OFFSET);       \</span>
<a name="l00185"></a>00185 <span class="preprocessor">                barrier();                                   \</span>
<a name="l00186"></a>00186 <span class="preprocessor">        } while (0)</span>
<a name="l00187"></a>00187 <span class="preprocessor"></span><span class="preprocessor">#  else</span>
<a name="l00188"></a>00188 <span class="preprocessor"></span><span class="preprocessor">#    define cpu_irq_enable()     __enable_interrupt()</span>
<a name="l00189"></a>00189 <span class="preprocessor"></span><span class="preprocessor">#    define cpu_irq_disable()    __disable_interrupt()</span>
<a name="l00190"></a>00190 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00191"></a>00191 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00192"></a>00192 <span class="preprocessor"></span>
<a name="l00193"></a><a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613">00193</a> <span class="keyword">typedef</span> uint32_t <a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a>;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 <span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> cpu_irq_save(<span class="keywordtype">void</span>)
<a name="l00196"></a>00196 {
<a name="l00197"></a>00197         <a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags;
<a name="l00198"></a>00198 
<a name="l00199"></a>00199         flags = sysreg_read(AVR32_SR);
<a name="l00200"></a>00200         cpu_irq_disable();
<a name="l00201"></a>00201 
<a name="l00202"></a>00202         <span class="keywordflow">return</span> flags;
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204 
<a name="l00205"></a>00205 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> cpu_irq_is_enabled_flags(<a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags)
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207         <span class="keywordflow">return</span> !(flags &amp; AVR32_SR_GM_MASK);
<a name="l00208"></a>00208 }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> cpu_irq_restore(<a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212         barrier();
<a name="l00213"></a>00213 <span class="preprocessor">#if defined(__ICCAVR32__)</span>
<a name="l00214"></a>00214 <span class="preprocessor"></span>   <span class="comment">// Barrier &quot; __asm__ __volatile__ (&quot;&quot;)&quot;</span>
<a name="l00215"></a>00215    <span class="comment">// Don&#39;t work with sysreg_write(AVR32_SR, flags)</span>
<a name="l00216"></a>00216    <span class="keywordflow">if</span>( cpu_irq_is_enabled_flags(flags) ) {
<a name="l00217"></a>00217       cpu_irq_enable();
<a name="l00218"></a>00218    }
<a name="l00219"></a>00219 <span class="preprocessor">#else</span>
<a name="l00220"></a>00220 <span class="preprocessor"></span>        sysreg_write(AVR32_SR, flags);
<a name="l00221"></a>00221 <span class="preprocessor">#endif</span>
<a name="l00222"></a>00222 <span class="preprocessor"></span>        barrier();
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a><a class="code" href="group__interrupt__group.html#gae1545a2473614564550b9c4015c94978">00225</a> <span class="preprocessor">#define cpu_irq_is_enabled()    cpu_irq_is_enabled_flags(sysreg_read(AVR32_SR))</span>
<a name="l00226"></a>00226 <span class="preprocessor"></span>
<a name="l00228"></a>00228 
<a name="l00229"></a>00229 
<a name="l00238"></a>00238 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> cpu_irq_level_is_enabled_flags(<a class="code" href="group__interrupt__group.html#ga9aa1f52defc97531b6343233abeea613" title="Type used for holding state of interrupt flag.">irqflags_t</a> flags,
<a name="l00239"></a>00239                 uint32_t level)
<a name="l00240"></a>00240 {
<a name="l00241"></a>00241         <span class="keywordflow">return</span> !(flags &amp; (1 &lt;&lt; level));
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 
<a name="l00253"></a><a class="code" href="group__interrupt__group.html#gaac8bab36e8dbe3b526b7869e18f827ea">00253</a> <span class="preprocessor">#define cpu_irq_level_is_enabled(level)                                  \</span>
<a name="l00254"></a>00254 <span class="preprocessor">        cpu_irq_level_is_enabled_flags(sysreg_read(AVR32_SR),             \</span>
<a name="l00255"></a>00255 <span class="preprocessor">                        TPASTE3(AVR32_SR_I, level, M_OFFSET))</span>
<a name="l00256"></a>00256 <span class="preprocessor"></span>
<a name="l00257"></a>00257 <span class="preprocessor">#if defined(__GNUC__) || defined(__DOXYGEN__)</span>
<a name="l00258"></a>00258 <span class="preprocessor"></span>
<a name="l00265"></a>00265 <span class="preprocessor">#  define cpu_irq_enable_level(level)                                    \</span>
<a name="l00266"></a>00266 <span class="preprocessor">        do {                                                             \</span>
<a name="l00267"></a>00267 <span class="preprocessor">                barrier();                                               \</span>
<a name="l00268"></a>00268 <span class="preprocessor">                __builtin_csrf(TPASTE3(AVR32_SR_I, level, M_OFFSET));    \</span>
<a name="l00269"></a>00269 <span class="preprocessor">        } while (0)</span>
<a name="l00270"></a>00270 <span class="preprocessor"></span>
<a name="l00278"></a>00278 <span class="preprocessor">#  define cpu_irq_disable_level(level)                                   \</span>
<a name="l00279"></a>00279 <span class="preprocessor">        do {                                                             \</span>
<a name="l00280"></a>00280 <span class="preprocessor">                __builtin_ssrf(TPASTE3(AVR32_SR_I, level, M_OFFSET));    \</span>
<a name="l00281"></a>00281 <span class="preprocessor">                barrier();                                               \</span>
<a name="l00282"></a>00282 <span class="preprocessor">        } while (0)</span>
<a name="l00283"></a>00283 <span class="preprocessor"></span>
<a name="l00284"></a>00284 <span class="preprocessor">#elif (defined __ICCAVR32__)</span>
<a name="l00285"></a>00285 <span class="preprocessor"></span><span class="preprocessor">#  define cpu_irq_enable_level(level)                                          \</span>
<a name="l00286"></a>00286 <span class="preprocessor">        do {                                                                   \</span>
<a name="l00287"></a>00287 <span class="preprocessor">                barrier();                                                     \</span>
<a name="l00288"></a>00288 <span class="preprocessor">                __clear_status_flag(TPASTE3(AVR32_SR_I, level, M_OFFSET));     \</span>
<a name="l00289"></a>00289 <span class="preprocessor">        } while(0)</span>
<a name="l00290"></a>00290 <span class="preprocessor"></span><span class="preprocessor">#  define cpu_irq_disable_level(level)                                         \</span>
<a name="l00291"></a>00291 <span class="preprocessor">        do {                                                                   \</span>
<a name="l00292"></a>00292 <span class="preprocessor">                __set_status_flag(TPASTE3(AVR32_SR_I, level, M_OFFSET));       \</span>
<a name="l00293"></a>00293 <span class="preprocessor">                barrier();                                                     \</span>
<a name="l00294"></a>00294 <span class="preprocessor">        } while (0)</span>
<a name="l00295"></a>00295 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00296"></a>00296 <span class="preprocessor"></span>
<a name="l00298"></a>00298 
<a name="l00300"></a>00300 
<a name="l00306"></a><a class="code" href="group__interrupt__deprecated__group.html#gaebdc47e7800e11d79b9e5e2da1fecaa6">00306</a> <span class="preprocessor">#define Enable_global_interrupt()            cpu_irq_enable()</span>
<a name="l00307"></a><a class="code" href="group__interrupt__deprecated__group.html#ga4834270e1b8984fe025bce15e7ae1564">00307</a> <span class="preprocessor"></span><span class="preprocessor">#define Disable_global_interrupt()           cpu_irq_disable()</span>
<a name="l00308"></a><a class="code" href="group__interrupt__deprecated__group.html#gab7b13c60d26b190e73e540586f1868f8">00308</a> <span class="preprocessor"></span><span class="preprocessor">#define Is_global_interrupt_enabled()        cpu_irq_is_enabled()</span>
<a name="l00309"></a>00309 <span class="preprocessor"></span>
<a name="l00310"></a><a class="code" href="group__interrupt__deprecated__group.html#gaf356f020be969d92c1761afcb98cbc5b">00310</a> <span class="preprocessor">#define Enable_interrupt_level(level)        cpu_irq_enable_level(level)</span>
<a name="l00311"></a><a class="code" href="group__interrupt__deprecated__group.html#ga8bd9b64c87e586fccd12bc168117ec7e">00311</a> <span class="preprocessor"></span><span class="preprocessor">#define Disable_interrupt_level(level)       cpu_irq_disable_level(level)</span>
<a name="l00312"></a><a class="code" href="group__interrupt__deprecated__group.html#ga2da97a4e1ac3493674ecf983dcecaa38">00312</a> <span class="preprocessor"></span><span class="preprocessor">#define Is_interrupt_level_enabled(level)    cpu_irq_level_is_enabled(level)</span>
<a name="l00313"></a>00313 <span class="preprocessor"></span>
<a name="l00323"></a><a class="code" href="group__interrupt__deprecated__group.html#ga6614d1866189f3f0c9a66e5c18e6a261">00323</a> <span class="preprocessor">#define AVR32_ENTER_CRITICAL_REGION()                                          \</span>
<a name="l00324"></a>00324 <span class="preprocessor">        {                                                                      \</span>
<a name="l00325"></a>00325 <span class="preprocessor">                bool global_interrupt_enabled = Is_global_interrupt_enabled(); \</span>
<a name="l00326"></a>00326 <span class="preprocessor">                Disable_global_interrupt();</span>
<a name="l00327"></a>00327 <span class="preprocessor"></span>
<a name="l00334"></a><a class="code" href="group__interrupt__deprecated__group.html#ga85b7f1705a7949f2e8dfacb071e00c6a">00334</a> <span class="preprocessor">#define AVR32_LEAVE_CRITICAL_REGION()                                          \</span>
<a name="l00335"></a>00335 <span class="preprocessor">                if (global_interrupt_enabled) Enable_global_interrupt();       \</span>
<a name="l00336"></a>00336 <span class="preprocessor">        }</span>
<a name="l00337"></a>00337 <span class="preprocessor"></span>
<a name="l00339"></a>00339 
<a name="l00341"></a>00341 
<a name="l00342"></a>00342 <span class="preprocessor">#endif </span><span class="comment">/* UTILS_INTERRUPT_INTERRUPT_H */</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Tue Nov 29 2011 17:59:31 for OpenShoe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
